package com.itheima.manager;/*
 * @author  xs
 * @date 2022/1/16 0:35
 * @Version  1.0
 * */

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.vo.BlackGroupVo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.UserPointVo;
import com.itheima.service.db.BackGroupService;
import com.itheima.service.db.UserInfoService;
import com.itheima.service.mongo.UserLocaleService;
import com.itheima.service.mongo.UserLocationService;
import com.itheima.util.DateFormatUtil;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class BlackUserManager {
@DubboReference
private BackGroupService backGroupService;
      //用户管理
    public ResponseEntity findAllUser(Integer page, Integer pagesize) {
//        分页查询
        PageBeanVo allUser = backGroupService.findAllUser(page, pagesize);
//           获得List集合
        List<UserInfo> userInfoList = (List<UserInfo>) allUser.getItems();
//        封装Vo
        ArrayList<BlackGroupVo> blackGroupVos = new ArrayList<BlackGroupVo>();
        if (CollectionUtil.isNotEmpty(userInfoList)){
            for (UserInfo userInfo : userInfoList) {
//                创建返回对象
                BlackGroupVo vo = new BlackGroupVo();
                vo.setId(userInfo.getId());//用户id
                vo.setAvatar(userInfo.getAvatar());//头像
                vo.setNickName(userInfo.getNickname());
                vo.setGender(userInfo.getGender());//性别
                vo.setAge(userInfo.getAge());
                vo.setCity(userInfo.getCity());
                vo.setCreated(DateUtil.formatDate(userInfo.getCreated()));
               blackGroupVos.add(vo);
            }
        }
        allUser.setItems(blackGroupVos);
        return ResponseEntity.ok(allUser);
    }


    @DubboReference
    private UserLocaleService userLocaleService;
    @DubboReference
    private UserInfoService userInfoService;
//    用户地点
    public ResponseEntity findUserlocale(Long uid) {
//        根据用户id查询出地理位置
        UserPointVo localeById = userLocaleService.findLocaleById(uid);
        System.out.println("地理位置：："+localeById);
        //用户信息
        UserInfo userInfo = userInfoService.findByUserId(uid);
//        创建Vo对象
        UserPointVo userPointVo = new UserPointVo();
        userPointVo.setUserId(userInfo.getId());
        userPointVo.setAvatar(userInfo.getAvatar());
        userPointVo.setNickName(userInfo.getNickname());
        userPointVo.setLongitude(localeById.getLongitude());
        userPointVo.setLatitude(localeById.getLatitude());
        userPointVo.setAddress(localeById.getAddress());
        return ResponseEntity.ok(userPointVo);
    }
}
